package net.ywd.xp1024search.config;

import lombok.ToString;
import net.ywd.xp1024search.entity.Category;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author Dreamingodd
 * @Date 2017/4/19.
 */
@Component
@ConfigurationProperties(prefix = "category")
@ToString
public class CategoryProperties {
    private List<Map<String, String>> categories = new ArrayList<>();

    public Map<String, Category> getCategoryMap() {
        Map<String, Category> categoryMap = new HashMap<>();
        for (Map<String, String> categoryConfig : categories) {
            Category category = new Category();
            category.setName(categoryConfig.get("name"));
            category.setLink(categoryConfig.get("link"));
            category.setPageCount(Integer.parseInt(categoryConfig.get("pageCount")));
            categoryMap.put(categoryConfig.get("name"), category);
        }
        return categoryMap;
    }

    public List<Map<String, String>> getCategories() {
        return categories;
    }

    public void setCategories(List<Map<String, String>> categories) {
        this.categories = categories;
    }
}
